### Makefile.in
## Author: <lukehuang.ca@gmail.com>
## Version: $Id: Makefile.in 63 2011-09-14 03:42:33Z lukehuang.ca $

.PHONY: default clean dist-clean

default: $(PDF_TARGETS)

clean:
	@echo "  RM pdf ps"
	@rm -f *.{ps,pdf}

distclean:
	@echo "  RM pdf ps"
	@rm -f *.{ps,pdf}
	@echo "  RM AUX LOG OUT TOC"
	@rm -f *.aux *.log *.out *.toc *.d

dist-clean:
	@echo "  RM pdf ps and auxiliary files"
	@rm -f *.{d,ps,pdf,aux,toc,log,out,bbl,blg,lol,lof,lot}

ifdef V
  ifeq ("$(origin V)", "command line")
    BUILD_VERBOSE = $(V)
  endif
endif
ifndef BUILD_VERBOSE
  BUILD_VERBOSE = 0
endif

ifeq ($(BUILD_VERBOSE),1)
  q =
  Q =
  O = $(shell tty)
else
  q = q_
  Q = @
  O = /dev/null
endif

echo-cmd = $(if $($(q)cmd_$(1)), echo '  $($(q)cmd_$(1))';)
     cmd = @$(echo-cmd) $(cmd_$(1))

q_cmd_TeX	?= TeX 		$(PWD)/$<
  cmd_TeX	?= $(TeX)	$< >$(O)

%.d: %.tex
	@set -e; rm -f $@;						\
	awk 'BEGIN { printf("%s %s: %s ", 				\
			    "$(<:.tex=.pdf)", "$(<:.tex=.d)", "$<") }	\
	     /(\input|\include)/					\
	     	   { printf("%s ", gensub(/.*{(.*)}.*/,			\
			 "\\1.tex ", "g")) }				\
	     END   { printf("\n") }' $< >$@

master_tex=$(PDF_TARGETS:.pdf=.tex)
-include $(master_tex:.tex=.d)

### For figures

q_cmd_dia	?= DIA EXPORT	$(PWD)/$<
  cmd_dia	?= $(DIAEXP)	-e $@ -t eps $< >$(O)
q_cmd_epstopdf	?= EPSTOPDF	$(PWD)/$<
  cmd_epstopdf	?= $(EPSTOPDF)	$< >$(0)
